fix(file-dropzone): fix multi-folder drop losing all but first folder#1340
fix(file-dropzone): fix multi-folder drop losing all but first folder#1340iOvergaard wants to merge 1 commit intomainfrom
Conversation
… first await DataTransferItem.webkitGetAsEntry() returns null after the first await because the browser expires the drag data store. By collecting all FileSystemEntry references in a synchronous pass first, all dropped folders are processed — not just the first one. Also removes _processFileEntry which used DataTransferItem.getAsFile() (same staleness issue), replaced by FileSystemFileEntry.file().
|
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1340.westeurope.azurestaticapps.net |
There was a problem hiding this comment.
Pull request overview
Ports the v1 fix for uui-file-dropzone to main (v2), addressing a browser DataTransfer staleness issue that caused multi-folder drops to only process the first folder by collecting FileSystemEntry references synchronously before any await.
Changes:
- Refactors
_getAllEntriesinto a synchronous “collect refs” phase plus an async_processRootEntriesphase to avoidDataTransferItem.webkitGetAsEntry()staleness. - Replaces root-level
DataTransferItem.getAsFile()handling withFileSystemFileEntry.file()via_getAsFile. - Adds 4 unit tests for
_processRootEntriescovering folders/files and accept/reject behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/components/file-dropzone/file-dropzone.element.ts | Refactors drop processing to avoid DataTransfer invalidation and supports root-level files/folders via stable FileSystemEntry refs. |
| src/components/file-dropzone/file-dropzone.test.ts | Adds unit tests for the new _processRootEntries behavior. |
Comments suppressed due to low confidence (1)
src/components/file-dropzone/file-dropzone.element.ts:158
_getEntrynow returnsFileSystemEntry | null, but the local variable is still typed/named as a directory (let dir: FileSystemDirectoryEntry | null) and the result ofwebkitGetAsEntry()is cast toFileSystemDirectoryEntry. This is now type-incorrect (root items can be files) and undermines type safety for callers. Update the local variable/casts to useFileSystemEntry | null(and consider renamingdir), so the implementation matches the new return type.
private _getEntry(entry: DataTransferItem): FileSystemEntry | null {
let dir: FileSystemDirectoryEntry | null = null;
if ('webkitGetAsEntry' in entry) {
dir = entry.webkitGetAsEntry() as FileSystemDirectoryEntry;
| @@ -165,7 +151,7 @@ export class UUIFileDropzoneElement extends LabelMixin('', LitElement) { | |||
| * Get the directory entry from a DataTransferItem. | |||
There was a problem hiding this comment.
The JSDoc for _getEntry still says it returns a "directory entry", but the method now returns FileSystemEntry (can be a file or directory). Updating the doc comment/wording would avoid confusion for future readers.
| * Get the directory entry from a DataTransferItem. | |
| * Get the FileSystemEntry (file or directory) from a DataTransferItem. |
|
Superseded by the forward-merge of v1/dev into main. |



Summary
Port of #1339 (targeting
v1/dev) tomainfor v2 tracking.Fixes the
DataTransferstaleness bug inuui-file-dropzonethat caused only the first dropped folder to be processed when multiple folders were dragged and dropped simultaneously.See #1339 for the full description, root cause analysis, and Mermaid diagrams.
Test plan
_processRootEntries— all pass